import Vue from 'vue'
import App from './App.vue'

// 引入全局css初始化
import 'Css/reset.css'

// 引入rem
import 'Utils/rem'

// 引入路由
import router from './router'

// 全局守卫
router.beforeEach((to, from, next) => {
    // 验证身份
    next()
})

// 引入过滤器
import * as filters from 'Filters/index'
Object.keys(filters).forEach(key => {
    Vue.filter(key, filters[key])
})

// 引入vuex
import store from 'Store/index'

// 引入全局变量(被vuex取替)
// import globalData from './config'
// Vue.prototype.$globalData = globalData

// 引入滑动插件
import VueTouch from 'vue-touch'
Vue.use(VueTouch, { name: 'v-touch' })

// 引入vant-ui
import {
    Tabbar,
    TabbarItem,
    Icon,
    Search,
    Button,
    Loading, // 轻加载
    Toast, // 重加载
    Field,
    CellGroup,
    Row,
    Col,
    Notify,
    NavBar,
    Card,
    Tag,
    Dialog,
    Cell,
    Swipe,
    SwipeItem,
    Stepper,
    GoodsAction,
    GoodsActionIcon,
    GoodsActionButton,
    ImagePreview,
    Sku
} from 'vant'

Vue.use(Tabbar)
    .use(TabbarItem)
    .use(Icon)
    .use(Search)
    .use(Button)
    .use(Loading)
    .use(Toast)
    .use(Field)
    .use(CellGroup)
    .use(Row)
    .use(Col)
    .use(Notify)
    .use(NavBar)
    .use(Card)
    .use(Tag)
    .use(Dialog)
    .use(Cell)
    .use(Swipe)
    .use(SwipeItem)
    .use(Stepper)
    .use(GoodsAction)
    .use(GoodsActionIcon)
    .use(GoodsActionButton)
    .use(ImagePreview)
    .use(Sku)

// 引入axios
import axios from 'axios'

// 添加axios拦截器
axios.interceptors.request.use(function(config) {
    // 请求发送之前做的事情
    Toast.loading({
        mask: true,
        message: '加载中...'
    })
    return config
}, function(error) {
    return Promise.reject(error)
})

axios.interceptors.response.use(function(response) {
    // 请求发送之后做的事情
    Toast.clear()
    return response
}, function(error) {
    return Promise.reject(error)
})

Vue.config.productionTip = false

const Vm = new Vue({
    render: h => h(App),
    router,
    store
}).$mount('#app')

export default Vm